home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Applications
/
GraphicViewers
/
pCD
/
Source
/
hpcdtoppm.0.4
/
color.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-23
|
4KB
|
237 lines
/* hpcdtoppm (Hadmut's pcdtoppm) v0.4
* Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
* Permission to use and distribute this software and its
* documentation for noncommercial use and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation. It is not allowed to sell this software in
* any way. This software is not public domain.
*/
#include "hpcdtoppm.h"
extern int RGB_BitSh1,RGB_Maximum1;
extern int RGB_F_LL;
extern int RGB_F_C1,RGB_O_C1;
extern int RGB_F_C2,RGB_O_C2;
extern int RGB_F_G1,RGB_F_G2,RGB_O_G;
extern uBYTE RGB_corr0[],RGB_corr1[],RGB_corr2[];
static uBYTE *RGB_corr=0;
static void ycctorgb();
static void monocorr();
static void initcorr()
{
switch(corrmode)
{case C_LINEAR: RGB_corr=RGB_corr0; break;
case C_DARK: RGB_corr=RGB_corr1; break;
case C_BRIGHT: RGB_corr=RGB_corr2; break;
default: error(E_INTERN);
}
}
void colconvert(wp,hp,l,c1,c2)
dim *wp,*hp;
implane *l,*c1,*c2;
#define w (*wp)
#define h (*hp)
{
melde("colconvert\n");
if((!l ) || ( l->iwidth != w ) || ( l->iheight != h) || (! l->im)) error(E_INTERN);
if(!monochrome)
{
if((!c1) || (c1->iwidth != w ) || (c1->iheight != h) || (!c1->im)) error(E_INTERN);
if((!c2) || (c2->iwidth != w ) || (c2->iheight != h) || (!c2->im)) error(E_INTERN);
}
if (do_crop) cropit(wp,hp,l,c1,c2);
if (do_sharp) sharpit(l);
switch (outfor)
{
case O_PS:
case O_EPS:
case O_PPM: ycctorgb(w,h,l,c1,c2);
break;
case O_PSG:
case O_EPSG:
case O_PGM: monocorr(w,h,l);
break;
case O_YCC:
break;
default: error(E_INTERN);
}
#undef w
#undef h
}
static long T_L[256],T_R[256],T_G[256],T_g[256],T_B[256];
static void initctable()
{long i;
static int init=0;
if(init) return;
init=1;
initcorr();
for(i=0;i<256;i++)
{ T_L[i] = i * RGB_F_LL;
T_R[i] = i * RGB_F_C2 + RGB_O_C2;
T_G[i] = i * RGB_F_G1;
T_g[i] = i * RGB_F_G2 + RGB_O_G;
T_B[i] = i * RGB_F_C1 + RGB_O_C1;
}
}
static void ycctorgb(w,h,l,c1,c2)
dim w,h;
implane *l,*c1,*c2;
{dim x,y;
uBYTE *pl,*pc1,*pc2;
long red,green,blue;
long L;
melde("ycctorgb\n");
initctable();
for(y=0;y<h;y++)
{
pl = l->im + y * l->mwidth;
pc1= c1->im + y * c1->mwidth;
pc2= c2->im + y * c2->mwidth;
for(x=0;x<w;x++)
{
L = T_L[*pl];
red = (L + T_R[*pc2] )>>RGB_BitSh1;
green= (L + T_G[*pc1] + T_g[*pc2] )>>RGB_BitSh1;
blue = (L + T_B[*pc1] )>>RGB_BitSh1;
red = TRIF(red, 0,RGB_Maximum1,0,red, RGB_Maximum1);
green = TRIF(green,0,RGB_Maximum1,0,green,RGB_Maximum1);
blue = TRIF(blue ,0,RGB_Maximum1,0,blue, RGB_Maximum1);
*(pl++ )=RGB_corr[red];
*(pc1++)=RGB_corr[green];
*(pc2++)=RGB_corr[blue];
}
}
}
#undef BitShift
#define slen 3072
void sharpit(l)
implane *l;
{int x,y,h,w,mw,akk;
uBYTE f1[slen],f2[slen],*old,*akt,*ptr,*work,*help,*optr=0;
melde("sharpit\n");
if((!l) || (!l->im)) error(E_INTERN);
if(l->iwidth > slen) error(E_INTERN);
old=f1; akt=f2;
h=l->iheight;
w=l->iwidth;
mw=l->mwidth;
for(y=1;y<h-1;y++)
{
ptr=l->im+ y*mw;
optr=ptr-mw;
work=akt;
*(work++)= *(ptr++);
for(x=1;x<w-1;x++)
{ akk = 5*((int)ptr[0])- ((int)ptr[1]) - ((int)ptr[-1])
- ((int)ptr[mw]) - ((int)ptr[-mw]);
NORM(akk);
*(work++)=akk;
ptr++;
}
*(work++)= *(ptr++);
if(y>1)
for(x=0;x<w;x++)
optr[x] = old[x];
help=old;old=akt;akt=help;
}
akt=optr+mw;
for(x=0;x<w;x++)
*(akt++) = *(old++);
}
#undef slen
#include <math.h>
#define hoch(a,b) (exp((b)*log(a)))
static void initmtable()
{long i,h;
static int init=0;
if(init) return;
init=1;
initcorr();
for(i=0;i<256;i++)
{ h = (i * RGB_F_LL)>>RGB_BitSh1;
h = TRIF(h,0,RGB_Maximum1,0,h,RGB_Maximum1);
T_L[i]=RGB_corr[h];
}
}
static void monocorr(w,h,l)
dim w,h;
implane *l;
{dim x,y;
uBYTE *ptr;
melde("monocorr\n");
initmtable();
for(y=0;y<h;y++)
{
ptr= l->im + y * l->mwidth;
for(x=0;x<w;x++,ptr++)
{ *ptr = T_L[*ptr];
}
}
}